home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 14.5 KB | 511 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: SLBitmap.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef SLPALETE_H
- #include "SLPalete.h"
- #endif
-
- #ifndef SLBITMAP_H
- #include "SLBitmap.h"
- #endif
-
- #ifndef PRBITMAP_H
- #include "PRBitmap.h"
- #endif
-
- #ifndef PRPICTUR_H
- #include "PRPictur.h"
- #endif
-
- #ifndef FWODEXCE_H
- #include "FWODExce.h"
- #endif
-
- #ifndef FWSTRMRW_H
- #include "FWStrmRW.h"
- #endif
-
- #ifndef FWCOLOR_H
- #include "FWColor.h"
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_Bitmap
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_CreateFromBits
- //----------------------------------------------------------------------------------------
-
- FW_HBitmap SL_API FW_PrivBitmap_CreateFromBits(
- short width, short height, short pixelSize, FW_Palette palette,
- void* image, long imageSize, short rowBytes,
- FW_PlatformError* error)
- {
- FW_ERR_TRY
- {
- return FW_NEW(FW_CPrivBitmapRep, (width, height, pixelSize, palette, image, imageSize, rowBytes));
- }
- FW_ERR_CATCH
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_CreateFromPlatformBitmap
- //----------------------------------------------------------------------------------------
-
- FW_HBitmap SL_API FW_PrivBitmap_CreateFromPlatformBitmap(
- FW_PlatformBitmap platformBitmap,
- FW_PlatformError* error)
- {
- FW_ERR_TRY
- {
- return FW_NEW(FW_CPrivBitmapRep, (platformBitmap));
- }
- FW_ERR_CATCH
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_CreateFromResource
- //----------------------------------------------------------------------------------------
-
- FW_HBitmap SL_API FW_PrivBitmap_CreateFromResource(
- FW_OResourceFile* resourceFile,
- FW_ResourceID resID,
- FW_PlatformError* error)
- {
- FW_ERR_TRY
- {
- return FW_NEW(FW_CPrivBitmapRep, (resourceFile, resID));
- }
- FW_ERR_CATCH
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_Copy
- //----------------------------------------------------------------------------------------
-
- FW_HBitmap SL_API FW_PrivBitmap_Copy(FW_HBitmap bitmap, const FW_SRect& srcRect, FW_PlatformError* error)
- {
- FW_ASSERT(bitmap);
-
- FW_ERR_TRY
- {
- return FW_NEW(FW_CPrivBitmapRep, (*bitmap, srcRect));
- }
- FW_ERR_CATCH
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_IsEqual
- //----------------------------------------------------------------------------------------
-
- FW_Boolean SL_API FW_PrivBitmap_IsEqual(FW_HBitmap bitmap, FW_HBitmap bitmap2)
- {
- FW_ASSERT(bitmap);
- FW_ASSERT(bitmap2);
-
- // No try block necessary - Do not throw
- return bitmap->IsEqual(*bitmap2);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_Read
- //----------------------------------------------------------------------------------------
-
- FW_HBitmap SL_API FW_PrivBitmap_Read(
- FW_HReadableStream hStream,
- FW_Boolean bDIBFileHeader,
- FW_PlatformError* error)
- {
- FW_ERR_TRY
- {
- FW_CReadableStream stream(hStream);
- return FW_NEW(FW_CPrivBitmapRep, (stream, bDIBFileHeader));
- }
- FW_ERR_CATCH
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_Write
- //----------------------------------------------------------------------------------------
-
- void SL_API FW_PrivBitmap_Write(
- FW_HBitmap bitmap,
- FW_HWritableStream hStream,
- FW_Boolean bDIBFileHeader,
- FW_PlatformError* error)
- {
- FW_ASSERT(bitmap);
-
- FW_ERR_TRY
- {
- FW_CWritableStream stream(hStream);
- bitmap->Write(stream, bDIBFileHeader);
- }
- FW_ERR_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_Acquire
- //----------------------------------------------------------------------------------------
-
- void SL_API FW_PrivBitmap_Acquire(FW_HBitmap bitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- bitmap->Acquire();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_GetRefCount
- //----------------------------------------------------------------------------------------
-
- long SL_API FW_PrivBitmap_GetRefCount(FW_HBitmap bitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- return bitmap->GetRefCount();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_Release
- //----------------------------------------------------------------------------------------
-
- void SL_API FW_PrivBitmap_Release(FW_HBitmap bitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- bitmap->Release();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_GetPlatformBitmap
- //----------------------------------------------------------------------------------------
-
- FW_PlatformBitmap SL_API FW_PrivBitmap_GetPlatformBitmap(FW_HBitmap bitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- return bitmap->GetPlatformBitmap();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_IsPlatformBitmapOrphan
- //----------------------------------------------------------------------------------------
-
- FW_Boolean SL_API FW_PrivBitmap_IsPlatformBitmapOrphan(FW_HBitmap bitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- return bitmap->IsPlatformBitmapOrphan();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_OrphanPlatformBitmap
- //----------------------------------------------------------------------------------------
-
- FW_PlatformBitmap SL_API FW_PrivBitmap_OrphanPlatformBitmap(FW_HBitmap bitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- return bitmap->OrphanPlatformBitmap();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_SetPlatformBitmap
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivBitmap_SetPlatformBitmap(FW_HBitmap bitmap, FW_PlatformBitmap newBitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- bitmap->SetPlatformBitmap(newBitmap);
- return FW_xNoError;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_AdoptPlatformBitmap
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivBitmap_AdoptPlatformBitmap(FW_HBitmap bitmap, FW_PlatformBitmap newBitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- bitmap->AdoptPlatformBitmap(newBitmap);
- return FW_xNoError;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_GetPalette
- //----------------------------------------------------------------------------------------
-
- FW_Palette SL_API FW_PrivBitmap_GetPalette(FW_HBitmap bitmap, FW_PlatformError* error)
- {
- FW_ASSERT(bitmap);
-
- FW_ERR_TRY
- {
- return bitmap->GetPalette();
- }
- FW_ERR_CATCH
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_SetPalette
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivBitmap_SetPalette(FW_HBitmap bitmap, FW_Palette palette)
- {
- FW_ASSERT(bitmap);
-
- FW_RETURN_ERR_TRY
- {
- bitmap->SetPalette(palette);
- }
- FW_RETURN_ERR_CATCH
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_GetBitmapInfo
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivBitmap_GetBitmapInfo(
- FW_HBitmap bitmap,
- short& width,
- short& height,
- short& rowBytes,
- short& pixelSize)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- bitmap->GetBitmapInfo(width, height, rowBytes, pixelSize);
- return FW_xNoError;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_GetBitmapBoundsGC
- //----------------------------------------------------------------------------------------
-
- void SL_API FW_PrivBitmap_GetBitmapBoundsGC(Environment* ev, FW_HBitmap bitmap, FW_SGraphicContext& gc, FW_SRect& bounds)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- bitmap->GetBitmapBoundsGC(ev, gc, bounds);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_GetBitmapBounds
- //----------------------------------------------------------------------------------------
-
- void SL_API FW_PrivBitmap_GetBitmapBounds(FW_HBitmap bitmap, FW_SRect& bounds)
- {
- FW_ASSERT(bitmap);
-
- bitmap->GetBitmapBounds(bounds);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_GetPixelColor
- //----------------------------------------------------------------------------------------
-
- void SL_API FW_PrivBitmap_GetPixelColor(FW_HBitmap bitmap,
- short horiz,
- short vert,
- FW_SColor& color)
- {
- FW_ASSERT(bitmap);
-
- FW_CColor pixelColor;
- bitmap->GetPixelColor(horiz, vert, pixelColor);
- color = pixelColor;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_SetPixelColor
- //----------------------------------------------------------------------------------------
-
- void SL_API FW_PrivBitmap_SetPixelColor(FW_HBitmap bitmap,
- short horiz,
- short vert,
- const FW_SColor& color)
- {
- FW_ASSERT(bitmap);
-
- bitmap->SetPixelColor(horiz, vert, color);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_ChangeBitmap
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivBitmap_ChangeBitmap(FW_HBitmap bitmap,
- void* image,
- long imageSize,
- short rowBytes,
- short width,
- short height,
- short pixelSize,
- FW_Boolean bScale)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- return bitmap->ChangeBitmap(image, imageSize, rowBytes, width, height, pixelSize, bScale);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_ChangeBitmapGeometry
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivBitmap_ChangeBitmapGeometry(FW_HBitmap bitmap,
- short width,
- short height,
- short pixelSize,
- FW_Boolean bScale)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- return bitmap->ChangeBitmap(width, height, pixelSize, bScale);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_SetImage
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivBitmap_SetImage(FW_HBitmap bitmap,
- void* image,
- long imageSize,
- short rowBytes)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- return bitmap->SetImage(image, imageSize, rowBytes);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_CopyPixels
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivBitmap_CopyPixels(
- FW_HBitmap bitmapSrc,
- FW_HBitmap bitmapDst,
- FW_SRect& boundsSrc,
- FW_SRect& boundsDst)
- {
- FW_ASSERT(bitmapSrc);
- FW_ASSERT(bitmapDst);
-
- // No try block necessary - Do not throw
- return bitmapSrc->CopyPixels(*bitmapDst, boundsSrc, boundsDst);
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_MacCreateFromPicture
- //----------------------------------------------------------------------------------------
-
- FW_HBitmap SL_API FW_PrivBitmap_MacCreateFromPicture(
- FW_HPicture picture, FW_SColor fillColor,
- const FW_SRect& pictPart, FW_PlatformError* error)
- {
- FW_ASSERT(picture);
-
- FW_ERR_TRY
- {
- return FW_NEW(FW_CPrivBitmapRep, (picture, fillColor, pictPart));
- }
- FW_ERR_CATCH
- return NULL;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_MacGetAsPicture
- //----------------------------------------------------------------------------------------
-
- FW_HPicture SL_API FW_PrivBitmap_MacGetAsPicture(FW_HBitmap bitmap,
- const FW_SRect& bounds,
- FW_PlatformError* error)
- {
- FW_ASSERT(bitmap);
-
- FW_ERR_TRY
- {
- return bitmap->MacGetAsPicture(bounds);
- }
- FW_ERR_CATCH
- return 0;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_MacLockPixels
- //----------------------------------------------------------------------------------------
-
- PixMapHandle SL_API FW_PrivBitmap_MacLockPixels(FW_HBitmap bitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- return bitmap->MacLockPixels(); // return NULL if fails
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_MacUnlockPixels
- //----------------------------------------------------------------------------------------
-
- FW_PlatformError SL_API FW_PrivBitmap_MacUnlockPixels(FW_HBitmap bitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- bitmap->MacUnlockPixels();
- return FW_xNoError;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_PrivBitmap_MacIsPixelsLocked
- //----------------------------------------------------------------------------------------
-
- FW_Boolean SL_API FW_PrivBitmap_MacIsPixelsLocked(FW_HBitmap bitmap)
- {
- FW_ASSERT(bitmap);
-
- // No try block necessary - Do not throw
- return bitmap->MacIsPixelsLocked();
- }
-
- #endif
-